<?php 
namespace Admin\Model;
use  \Think\Model;

class CategoryModel extends Model
{
		protected $cats = null;
 	 public function  __construct()
 	 {
 	 	parent::__construct();
 	 	$this->cats = $this->select();
 	 }

 	 public function getCatss($data =array(),$pid=0)
 	 {	
 	 	$data = $this->cats;
 	 	$tree = array();
 	 	foreach ($data as $v) 
 	 	{
 	 		
 	 			if($v['parent_id'] == $pid)
 	 			{
 	 				$son = $this->getCatss($data,$v['cat_id']);
 	 				
 	 				$v['child'] = $son;
 	 				$tree[] = $v;
 	 			}
 	 	}

 	 	return $tree;
 	 }

		public function getCats()
		{

			return $this->select();
		}

		public function getTree($data,$pid=0,$lev=0)
		{

				static $arr = array();
				
				foreach ($data as $v)
				 {
					
					if($v['parent_id'] == $pid)
					{	
						$v['lev'] = $lev;

						$arr [] = $v;

						$arr = $this->getTree($data,$v['cat_id'],$lev+1);
					}
				}

				return $arr;
		}

		public function getSonID($data,$cat_id)
		{
				static $son = array();

				foreach ($data as $v)
				 {
					if($v['parent_id'] == $cat_id)
					{
						$son[]=$v['cat_id'];

						 $son= $this->getSonID($data,$v['cat_id']);
					}
				}

				return $son;
		}
}		


 ?>